﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EstepLibrary;
using System.Data;

public partial class includes_footer : System.Web.UI.UserControl
{
    EstepLibrary.Veriler Kayitseti = new EstepLibrary.Veriler();
    EstepLibrary.Tool RSTool = new EstepLibrary.Tool();

    protected void Page_Load(object sender, EventArgs e)
    {
        fillAltMenu();

    }

    private void fillAltMenu()
    {
        string sorgu = "SELECT M.TIPKODU, M.MENUADI, M.MENUID, M.USTID, M.MENUID, M.URL, M.SEOURL, ISNULL(M.YENISAYFA,0) AS YENISAYFA, MT.* " +
                        "FROM MENULER M " +
                        "   LEFT JOIN MENUTIP MT ON MT.TIPKODU = M.TIPKODU " +
                        "WHERE ISNULL(M.POZALT,0)=1 AND ISNULL(OK,0)=1 AND ISNULL(AKTIF,0)=1 " +
                        "ORDER BY M.SIRAALT ASC, M.MENUADI ASC";
        rptAltMenu.DataSource = Kayitseti.GetDataSet(sorgu);
        rptAltMenu.DataBind();
    }

    protected void rptAltMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        bool YeniSayfa = Convert.ToBoolean(DataBinder.Eval(e.Item.DataItem, "YENISAYFA"));
        string currentMenuURL = getMenuURLByDataItem(e.Item.DataItem);
        HyperLink hp = e.Item.FindControl("lnkAlt") as HyperLink;
        hp.NavigateUrl = currentMenuURL; 
        if (YeniSayfa)
        {
            hp.Target = "_blank";
        }
    }

    private string getMenuURLByDataItem(object dataItem)
    {
        int TipKodu = Convert.ToInt32(DataBinder.Eval(dataItem, "TIPKODU"));
        int MENUID = Convert.ToInt32(DataBinder.Eval(dataItem, "MENUID"));
        int USTID = Convert.ToInt32(DataBinder.Eval(dataItem, "USTID"));
        string MenuURL = DataBinder.Eval(dataItem, "URL").ToString();
        string MenuSEOURL = DataBinder.Eval(dataItem, "SEOURL").ToString();
        string UrlString = "";

        switch (TipKodu)
        {
            case 1://düzmetin
                UrlString = "/kategori/" + MenuSEOURL + "-" + MENUID.ToString() + "-" + USTID.ToString() + ".html";
                break;
            case 2://haber tipi
                UrlString = "/icerikler/" + MenuSEOURL + "-" + MENUID.ToString() + "-" + USTID.ToString() + ".html";
                break;
            case 3://içerik başlık
                UrlString = "/basliklar/" + MenuSEOURL + "-" + MENUID.ToString() + "-" + USTID.ToString() + ".html";
                break;
            case 4://resim galerisi
                UrlString = "/resimler/" + MenuSEOURL + "-" + MENUID.ToString() + "-" + USTID.ToString() + ".html";
                break;
            case 5://yayın
                UrlString = "/yayinlar/" + MenuSEOURL + "-" + MENUID.ToString() + "-" + USTID.ToString() + ".html";
                break;
            case 6://dosya
                UrlString = "/dosyalar/" + MenuSEOURL + "-" + MENUID.ToString() + "-" + USTID.ToString() + ".html";
                break;
            case 7://iletişim formu
                UrlString = "iletisim.html";
                break;
            case 8://duyuru liste
                UrlString = "/duyurular/" + MenuSEOURL + "-" + MENUID.ToString() + "-" + USTID.ToString() + ".html";
                break;
            case 9://link yönlendirme
                UrlString = MenuURL;
                break;
            case 10://video galeri
                UrlString = "/videolar/" + MenuSEOURL + "-" + MENUID.ToString() + "-" + USTID.ToString() + ".html";
                break;

            default:
                UrlString = "about:blank";
                break;
        }

        return UrlString;

    }

}